package io.renren.modules.subway.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.UUID;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.subway.entity.LineEntity;
import io.renren.modules.subway.service.LinesService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 线路管理
 *
 * @author ${author}
 * @email ${email}
 * @date 2019-04-29 20:46:24
 */
@RestController
@RequestMapping("subway/lines")
public class LinesController {
    @Autowired
    private LinesService linesService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("subway:lines:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = linesService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{lineId}")
    @RequiresPermissions("subway:lines:info")
    public R info(@PathVariable("lineId") Long lineId){
        LineEntity lines = linesService.getById(lineId);

        return R.ok().put("lines", lines);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("subway:lines:save")
    public R save(@RequestBody LineEntity line){
        UUID uuid = UUID.randomUUID();
        line.setLineId(uuid.toString().replace("-", ""));
        linesService.save(line);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("subway:lines:update")
    public R update(@RequestBody LineEntity line){
        ValidatorUtils.validateEntity(line);
        linesService.updateById(line);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("subway:lines:delete")
    public R delete(@RequestBody Long[] ids){
        linesService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
